# ########################################################################
# This is a quick 'n' dirty script to grab the XMLDoc from a validation
# class and generate CodePlex wiki markup for the function, for the
# documentation.
# ########################################################################

# Read in file.
my $filename = shift @ARGV;
open my $fh, "< $filename" or die "Could not open $filename: $!";
my $content = join('', <$fh>);
close $fh;

# Rip off starting bit of class declaration up to after constructor, so we
# don't catch class or constructor summary.
$content =~ s/^.+?public \w+\(//s;

# Build data structure of summaries/names/variants.
my %found;
while ($content =~ /<summary>(.+?)<\/summary>.+?public \w+ (\w+)(\([^)]*\))/gs) {
	next if $2 eq 'Not';
	$found{$2} ||= {
		variants => [],
		summary => $1
	};
	push @{$found{$2}->{'variants'}}, "$2$3";
}

# Contents table.
print "!! Contents\n";
for (sort keys %found) {
	print "[#$_]\n";
}

# Entries.
for (sort keys %found) {
	my $variants = join("\n", @{$found{$_}->{'variants'}});
	$found{$_}->{'summary'} =~ s/\/\/\///g;
	$found{$_}->{'summary'} =~ s/\s+/ /g;
	$found{$_}->{'summary'} =~ s/^ //;
	print <<CONTENT;
{anchor:$_}
!!! $_
{code:c#}
$variants
{code:c#}
$found{$_}->{'summary'}
CONTENT
}

